﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Collections;


namespace TCCHWLib.Commands
{


    public class IF_Command : ICommand
    {
        int value;
        int index;
        

        public IF_Command()
        {
        }

        public override object Execute(Processor processor)
        {
            value = Convert.ToInt32(m_ExOperand1);
            index = Convert.ToInt32(m_Operand2);
            return null;
        }
        public override void UpdatePC(Processor processor)
        {
            if (value == 0)
            {
                processor.PC++;
            }
            else
            {
                processor.PC = index;
            }
        }
        public override string ToString()
        {
            string val1 = "";
            switch (m_Type1)
            {
                case ParameterType.Value:
                    val1 = "{" + m_Operand1 + "}";
                    break;
                case ParameterType.Address:
                    val1 = "[" + m_Operand1 + "]";
                    break;
                case ParameterType.Instruction:
                    val1 = "i" + m_Operand1;
                    break;
                case ParameterType.Null:
                    val1 = "NULL";
                    break;
                default:
                    val1 = m_Operand1.ToString();
                    break;
            }
            return String.Format("IF ( {0} )", val1);
            //return base.ToString() + String.Format("> next pc{0}", NextPC);
        }

    }
}
